package com.fire.eyes.controller;

import com.fire.core.base.controller.BaseController;
import com.fire.core.util.AjaxResult;
import com.fire.eyes.constants.ErrorCodeConstants;
import com.fire.eyes.model.FireSupervisorModel;
import com.fire.eyes.service.IAssetService;
import com.fire.eyes.validation.*;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @ClassName: EyesController
 * @Description: TODO
 * @Author raoyuxing
 * @Date 2019/1/7 16:30
 */
@Controller
public class SuperiorsController extends BaseController {
    private final static Logger blogin = Logger.getLogger(SuperiorsController.class);

    @Autowired
    private IAssetService assetService;


    /**
     * 功能描述: 我管理的消防单位
     * @param:
     * @return:
     * @auther: raoyuxing
     * @date: 2019/1/19 15:48
     */
    @PostMapping(value = "/mysuperiors")
    @ResponseBody
    public AjaxResult mysuperiors(@RequestBody @Validated TokenDTO tokenDTO, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            for (FieldError fieldError : bindingResult.getFieldErrors()) {
                System.out.println(fieldError.getDefaultMessage());
            }
            System.out.print("效验bu通过：）");
        }
        List<FireSupervisorModel> superiors = assetService.getSupervisorListByUser(tokenDTO);
        Map<String ,Object> map = new HashMap<>();
        map.put("supperlist",superiors);
        return ajaxResult(ErrorCodeConstants.SUCCESS, "成功", map,"成功");
    }

    /**
     * 功能描述: 我管理的消防单位详情
     * @param:
     * @return:
     * @auther: raoyuxing
     * @date: 2019/1/19 15:48
     */
    @PostMapping(value = "/mysuperiordetails")
    @ResponseBody
    public AjaxResult mysuperiordetails(@RequestBody @Validated SuperiorsDTO superiorsDTO, BindingResult bindingResult){
        if (bindingResult.hasErrors()) {
            for (FieldError fieldError : bindingResult.getFieldErrors()) {
                System.out.println(fieldError.getDefaultMessage());
            }
            System.out.print("效验bu通过：）");
        }
        FireSupervisorModel superior = assetService.getSupervisor(superiorsDTO);
        return ajaxResult(ErrorCodeConstants.SUCCESS, "成功", superior, "成功");
    }
}
